package com.scau.XFourPOS.model;

import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.Column;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

/**
 * 类名称：Product
 * 类描述：产品的model
 * 创建人：庄祥鹏
 * */
@Entity
@Table(name = "product")
public class Product {
	/**
	 * 产品id
	 */
	@Id
	@Column(name = "product_id", unique = true, nullable = false)
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private int productId;

	/**
	 * 产品条形码
	 */
	@Column(name = "code", length = 50)
	private String code;

	/**
	 * 产品名
	 */
	@Column(name = "name", length = 50)
	private String name;

	/**
	 * 产品描述
	 */
	@Column(name = "description")
	private String description;

	/**
	 * 产品类别， 多对一对应ProductCategory表，属于夹克、裤子或什么什么的
	 * cascade默认为无级联操作
	 * optional是否能为空，，默认为true
	 */
	
	@ManyToOne(cascade={CascadeType.MERGE,CascadeType.REFRESH},optional=true)
	private ProductCategory productCategory;
	/**
	 * 产品存货，一对多对应ProductStock表
	 * fetch:表示抓取策略,默认为FetchType.LAZY
	 */
	@Transient
	@OneToMany(cascade=CascadeType.ALL,mappedBy="productStockPK.product")
	private Set<ProductStock> productStock;
	
	/**
	 * 衣服价格
	 */
	@Column(name="price")
	private double price;
	
	private int amount;
	
	public int getAmount() {
		return amount;
	}

	public void setAmount(int amount) {
		this.amount = amount;
	}

	/**
	 * getter and setter
	 */
	public String getCode() {
		return code;
	}

	public int getProductId() {
		return productId;
	}

	public void setProductId(int productId) {
		this.productId = productId;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public ProductCategory getProductCategory() {
		return productCategory;
	}

	public void setProductCategory(ProductCategory productCategory) {
		this.productCategory = productCategory;
	}

	public Set<ProductStock> getProductStock() {
		return productStock;
	}

	public void setProductStock(Set<ProductStock> productStock) {
		this.productStock = productStock;
	}
	public double getPrice() {
		return price;
	}

	public void setPrice(double price) {
		this.price = price;
	}
}
